<template>
  <div class="case_page">
    <Menus title="案例库">
      <a @click="goback"
         href="javascript:void(0)"
         v-if="is_post">
        <div class="img_block">
          <img class="img_margin"
               src="/static/web/theme/gov_xinjiang_xinyuan/img/icon_fanhui.png"
               alt="返回">
        </div>
        <span>返回</span>
      </a>
      <router-link to="/"
                   v-if="is_post">
        <div class="img_block">
          <img class="img_margin"
               src="/static/web/theme/gov_xinjiang_xinyuan/img/icon_fanhuishouye.png"
               alt="返回首页">
        </div>
        <span>返回首页</span>
      </router-link>
    </Menus>
    <div class="main"
         v-if="!is_post">

      <div class="sidebar">
        <div class="sidebar_content">
          <ul>
            <li :class="{active:index==current}"
                v-for="(item, index) in case_sort"
                :key="'key-tab-menu-'+index"
                @click="switchTab(index)">{{item.title}}</li>
          </ul>
        </div>
      </div>
      <div class="c2">
        <ul>
          <li v-for="(item,index) in list[current]"
              :key="'key-case-list-'+index"
              @click="getPost(item.id)">
            <div class="title">{{item.title}}</div>
            <div class="intro"
                 v-if="item.anyou || item.court_name">
              <span v-if="item.anyou">
                <i>案由：</i> {{item.anyou}}</span>
              <span v-if="item.court_name">
                <i>法院：</i> {{item.court_name}}</span>
            </div>
          </li>
        </ul>
        <div class="foot">
          <div class="tip"
               v-if="page[current] && page[current].max">已经全部加载</div>
          <div class="more-link"
               v-else>
            <a href="javascript:void(0)"
               @click="loadMore(current)">加载更多</a>
          </div>
        </div>
      </div>
    </div>
    <div class="post-wrap"
         v-else>
      <div class="post"
           v-if="item">
        <div class="title">{{item.title}}</div>
        <div class="details"
             v-html="item.content"></div>
      </div>
    </div>
    <div class="case-info"
         v-if="is_post">
      <div class="ht">
        <span>案件信息</span>
      </div>
      <ul>
        <li>
          <strong>法院：</strong>
          <span>{{item.court_name || '-'}}</span>
        </li>
        <li>
          <strong>审判长：</strong>
          <span>{{item.presiding_judge || '-'}}</span>
        </li>
        <li>
          <strong>案例编号：</strong>
          <span>{{item.no || '-'}}</span>
        </li>
        <li>
          <strong>案由：</strong>
          <span>{{item.anyou || '-'}}</span>
        </li>
        <li>
          <strong>判决书类型：</strong>
          <span>{{item.verdict_type_name || '-'}}</span>
        </li>
        <li>
          <strong>第几审：</strong>
          <span> {{item.instance_type || '-'}}</span>
        </li>
        <li>
          <strong>判决日期：</strong>
          <span>{{item.judge_date || '-'}}</span>
        </li>

      </ul>
    </div>
  </div>
</template>
<script>
import Menus from '@/components/Menu'
import api from '@/datas/api'
import case_sort from '@/datas/case'
export default {
  data () {
    return {
      case_sort,
      is_post: false,
      scroll_top: 0,
      list: [],
      page: [],
      current: 0,
      item: ''
    }
  },

  methods: {
    goback () {
      this.is_post = false
      this.$scrollTo(this.scroll_top)
    },
    switchTab (i) {
      this.current = i
      this.$scrollTo()
    },
    async getPost (id) {
      const { errcode, item } = await this.$get(api.case_post + id, this)
      if (errcode) return
      this.scroll_top = document.documentElement.scrollTop
      this.item = item
      this.is_post = true
      this.$scrollTo()
    },
    async getLists (v, i) {
      let query = v.expert_id
        ? '?per_page=10&expert_id=' + v.expert_id
        : '?per_page=10'
      query = v.page ? query + '&page=' + v.page : query
      const { items } = await this.$get(api.case + query, this)
      this.list.push(items)
      this.page.push({ size: 1, max: items.length < 10 ? 1 : 0 })

      // this.requestList(v, i).then(items => {
      //   this.list.push(items)
      //   console.log('request:', i)
      //   this.page.push({ size: 1, max: items.length < 10 ? 1 : 0 })
      // })
    },
    loadMore () {
      let s = this.current
      let v = case_sort[s]
      v.page = this.page[s].size + 1
      this.requestList(v).then(items => {
        this.list[s].push(...items)
        this.page[s] = { size: v.page, max: items.length < 10 ? 1 : 0 }
      })
    },
    async requestList (v) {
      let query = v.expert_id
        ? '?per_page=10&expert_id=' + v.expert_id
        : '?per_page=10'
      query = v.page ? query + '&page=' + v.page : query
      const { items } = await this.$get(api.case + query, this)
      return items
    }
  },

  async mounted () {
    this.case_sort = case_sort
    for (let i = 0; i < case_sort.length; i++) {
      await this.getLists(case_sort[i])
    }
    // case_sort.map(this.getLists)
  },
  components: {
    Menus
  }
}
</script>
<style lang="scss">
.case_page {
  padding-top: 1.6rem;
  background: #ddd;
  .main {
    .c1 {
      width: 35vw;
      height: 100vh;
      background: #fff;
      .ht {
        padding: 0.3rem 0.3rem 0.15rem;
        font-size: 0.18rem;
        font-weight: bold;
        color: #808080;
      }
      .sub_nav {
        padding: 0 0.3rem;
        a {
          display: inline-block;
          padding: 0.1rem 0.2rem;
          font-size: 0.2rem;
          border: 1px solid #3d69bd;
          border-radius: 0.05rem;
          color: #3d69bd;
          margin: 0 0.1rem 0.1rem 0;
          &.current {
            background: #3d69bd;
            color: #fff;
          }
        }
      }
      .sub_list {
        padding: 0 0.3rem;
        a {
          display: inline-block;
          padding: 0.1rem 0.15rem;
          font-size: 0.18rem;
          color: #fff;
          background: #999;
          margin: 0 0.1rem 0.1rem 0;
          border-radius: 0.05rem;
          font-weight: normal;
          &.current {
            background: #3d69bd;
          }
        }
      }
    }
    .sidebar {
      top: 1.59rem;
      .sidebar_content {
        width: 90vw;
      }
    }
    .c2 {
      padding: 1.2rem 0 0.5rem;
      min-height: 100vh;
      ul {
        width: 1200px;
        margin: 0 auto;
        padding: 0;
        border-radius: 0.04rem;
        list-style: none;
        background: #fff;
        li {
          // background: #fff;
          font-size: 0.2rem;
          padding: 0.25rem;
          border-bottom: 1px solid #ccc;
          .title {
            font-size: 0.24rem;
            line-height: 1.8;
          }
          .intro {
            font-size: 0.16rem;
            color: #808080;
            span {
              margin-right: 0.15rem;
              i {
                color: #ccc;
                font-style: normal;
              }
            }
          }
          .tags {
            padding: 0.1rem 0.3rem;
            font-size: 0.16rem;
            background-color: rgba(0, 0, 0, 0.05);
            strong {
              font-size: 0.18rem;
              color: #808080;
            }
            a {
              padding: 0.07rem;
              color: #fff;
              background: #3d69bd;
              border-radius: 0.04rem;
              margin-right: 0.1rem;
              display: inline-block;
            }
          }
        }
      }
      .foot {
        padding: 0.6rem 0;
        font-size: 0.2rem;
        text-align: center;
        .tip {
          color: #666;
        }
        .more-link a {
          display: block;
          width: 2rem;
          height: 0.66rem;
          line-height: 0.66rem;
          margin: 0 auto;
          border: 1px solid #ccc;
          color: #666;
          background: #fff;
        }
      }
    }
  }
  .post {
    background: #fff;
    border-radius: 0.06rem;
    position: relative;
    .title {
      font-size: 0.32rem;
      text-align: center;
      padding: 0.8rem 0 0.3rem;
      margin: 0 0.8rem 0.5rem;
      border-bottom: 1px solid #ddd;
    }
    .details {
      padding: 0 0.8rem 0.8rem;
      font-size: 0.18rem;
      line-height: 1.7;
      p {
        margin-bottom: 0.25rem;
      }
    }
  }
  .post-wrap {
    padding: 0.6rem 0;
    margin: 0 auto;
    width: 10rem;
  }
  .case-info {
    width: 3.3rem;
    background: #fff;
    position: fixed;
    left: 50%;
    top: 2.2rem;
    border-radius: 6px;
    margin-left: 5.2rem;
    .ht {
      padding: 0.2rem 0.2rem 0;
      span {
        padding-left: 0.1rem;
        border-left: 0.08rem solid #3d69bd;
        font-size: 0.22rem;
      }
    }
    ul {
      padding: 0.2rem;
      list-style: none;
      font-size: 0.16rem;
      li {
        display: flex;
        padding: 0.1rem 0;
        border-top: 1px dotted #ddd;
        strong {
          width: 1rem;
          flex-shrink: 0;
          font-weight: normal;
          color: #808080;
        }
      }
    }
  }
}

@media screen and (orientation: portrait) {
  .case_page {
    .main {
      .sidebar {
        background: none;
        position: relative;
        height: auto;
        top: 0;
        margin: 0.55rem 0 0;
        .sidebar_content {
          ul {
            flex-wrap: wrap;
            li {
              width: 20%;
              border: 1px solid #ccc;
              background: #fff;
              font-size: 0.24rem;
              margin: 0 0.1rem 0.1rem 0;
              width: 1.8rem;
              border-radius: 0.1rem;
              &.active {
                background: #3d69bd;
                border-color: #3d69bd;
                color: #fff;
              }
            }
          }
        }
      }
      .c2 {
        padding-top: 0.5rem;
        ul {
          width: 90%;
          margin: 0 auto;
          border-radius: 0.1rem;
          box-shadow: 0.1rem 0.1rem 0.3rem rgba(0, 0, 0, 0.05);
        }
      }
    }
  }
  .detail_page .article_content {
    width: 90%;
    margin: 0.55rem auto;
    box-shadow: 0.1rem 0.1rem 0.3rem rgba(0, 0, 0, 0.05);
  }
}
@media screen and (orientation: landscape) {
}
</style>
